import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import Index from '@/views/reception/components/home'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   如果设置为 true，项目将不会显示在侧边栏中（默认为 false）
 * alwaysShow: true               如果设置为 true，将始终显示根菜单
 *                                如果不设置 alwaysShow，当 item 有多个子路由时，它将变成嵌套模式，否则不显示根菜单,
 *
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/reception',
    component: Index
    // hidden: true
  },
  {
    path: '/login',
    component: () => import('@/views/login/login'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '首页',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'el-icon-s-home' }
    }]
  },

  {
    path: '/example',
    component: Layout,
    redirect: '/example/userList',
    name: 'Example',
    meta: { title: '人员管理', icon: 'el-icon-menu' },
    children: [
      {
        path: 'userList',
        name: 'UserList',
        component: () => import('@/views/table/userList'),
        meta: { title: '用户', icon: 'el-icon-user' }
      },
      {
        path: 'userFrom',
        name: 'UserFrom',
        component: () => import('@/views/form/user/userFrom'),
        meta: { title: '信息', icon: 'table' }
      },
      {
        path: '/updateUser',
        name: 'UpdateUser',
        component: () => import('@/views/components/user/updateUser'),
        meta: { title: '修改信息', icon: 'table' },
        hidden: true
      }
    ]
  },

  {
    path: '/form',
    component: Layout,
    meta: { title: '文章管理', icon: 'table' },
    children: [
      {
        path: 'writeToArticle',
        name: 'WriteToArticle',
        component: () => import('@/views/components/article/writeToArticle.vue'),
        meta: { title: '写文章', icon: 'el-icon-tickets' }
      },
      {
        path: '/updateArticle',
        name: 'UpdateArticle',
        component: () => import('@/views/components/article/updateArticle'),
        meta: { title: '修改文章', icon: 'el-icon-tickets' },
        hidden: true
      },
      {
        path: 'article',
        name: 'Article',
        component: () => import('@/views/table/articleList'),
        meta: { title: '文章', icon: 'el-icon-tickets' }
      }
    ]
  },
  {
    path: '/Navigation',
    component: Layout,
    redirect: '/Navigation/sortNavigation',
    meta: { title: '导航管理', icon: 'el-icon-s-unfold' },
    children: [
      {
        path: 'sortNavigation',
        name: 'SortNavigation',
        component: () => import('@/views/table/sortNavigation'),
        meta: { title: '分类', icon: 'table' }
      },
      {
        path: 'labelNavigation',
        name: 'LabelNavigation',
        component: () => import('@/views/table/labelNavigation'),
        meta: { title: '标签', icon: 'table' }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/photo',
    component: Layout,
    redirect: '/photo',
    name: 'Nested',
    meta: {
      title: '照片管理',
      icon: 'nested'
    },
    children: [
      {
        path: 'photo1',
        component: () => import('@/views/photo/photo'), // Parent router-view
        name: '相册',
        meta: { title: '相册' },
        children: [
        ]
      },
      {
        path: 'menu2',
        component: () => import('@/views/nested/menu2/index'),
        meta: { title: '下拉菜单2' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
